def andAll(l):
	return reduce(lambda x, y: x and y, l)

def bisect_sub(A, x):
	"""
	>>> A = [1, 2, 3, 4]
	>>> print andAll(map(lambda x: bisect_sub(A, x), A))
	True
	>>> print bisect_sub(A, 2.5)
	False
	>>> print bisect_sub(A, -7)
	False
	>>> A = []
	>>> print bisect_sub(A, -7)
	False
	>>> A = [1, 2, 3, 4, 5]
	>>> print andAll(map(lambda x: bisect_sub(A, x), A))
	True
	>>> print bisect_sub(A, 2.5)
	False
	>>> print bisect_sub(A, -7)
	False
	"""
	if len(A) == 0:
		return False
	else:
		m = len(A) / 2
		if A[m] == x:
			return True
		elif A[m] > x:
			return bisect(A[:m], x)
		else: #A[m] < x
			return bisect(A[m+1:], x)

def bisect(A, x, l=0, u=None):
	"""
	>>> A = [1, 2, 3, 4]
	>>> print andAll(map(lambda x: bisect(A, x), A))
	True
	>>> print bisect(A, 2.5)
	False
	>>> print bisect(A, -7)
	False
	>>> A = []
	>>> print bisect(A, -7)
	False
	>>> A = [1, 2, 3, 4, 5]
	>>> print andAll(map(lambda x: bisect(A, x), A))
	True
	>>> print bisect(A, 2.5)
	False
	>>> print bisect(A, -7)
	False
	"""
	if u == None:
		u = len(A) - 1
	if l > u:
		return False
	else:
		m = l + (u-l) / 2
		if A[m] == x:
			return True
		elif A[m] > x:
			return bisect(A, x, l, m-1)
		else: #A[m] < x
			return bisect(A, x, m+1, u)

import doctest
doctest.testmod()
